LanguageExt.Core

LanguageExt.Core Immutable Collections Enumerable

Contents

record EnumerableM <A> (IEnumerable<A> runEnumerable) Source #

Lazy sequence

This is a lightweight wrapper around IEnumerable that also implements traits that make it play nice with other types in this library: Monad, Traversable, etc.

Parameters

type A

Type of the values in the sequence

Properties

property EnumerableM<A> Empty Source #

Empty sequence

property EnumerableM<A> AdditiveIdentity Source #

Constructors

constructor EnumerableM (ReadOnlySpan<A> ma) Source #

Constructor from lazy sequence

Methods

method int Count () Source #

method EnumerableM<A> Concat (IEnumerable<A> items) Source #

Add a range of items to the end of the sequence

Forces evaluation of the entire lazy sequence so the items can be appended.

method EnumerableM<A> Concat (EnumerableM<A> items) Source #

Add a range of items to the end of the sequence

Forces evaluation of the entire lazy sequence so the items can be appended.

method IEnumerable<A> AsEnumerable () Source #

Stream as an enumerable

method Unit Iter (Action<A> f) Source #

Impure iteration of the bound values in the structure

Parameters

returns

Returns the original unmodified structure

method Unit Iter (Action<A, int> f) Source #

Impure iteration of the bound values in the structure

Parameters

returns

Returns the original unmodified structure

method K<F, EnumerableM<B>> Traverse <F, B> (Func<A, K<F, B>> f) Source #

where F : Applicative<F>

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.

Parameters

type F

Applicative functor trait

type B

Bound value (output)

param f
param ta

Traversable structure

method EnumerableM<B> Map <B> (Func<A, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method EnumerableM<B> Map <B> (Func<A, int, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method EnumerableM<B> Select <B> (Func<A, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method EnumerableM<B> Select <B> (Func<A, int, B> f) Source #

Map the sequence using the function provided

Parameters

type B
param f

Mapping function

returns

Mapped sequence

method EnumerableM<B> Bind <B> (Func<A, EnumerableM<B>> f) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param f

Bind function

returns

Flat-mapped sequence

method EnumerableM<B> Bind <B> (Func<A, K<EnumerableM, B>> f) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param f

Bind function

returns

Flat-mapped sequence

method EnumerableM<B> SelectMany <B> (Func<A, EnumerableM<B>> bind) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method EnumerableM<C> SelectMany <B, C> (Func<A, EnumerableM<B>> bind, Func<A, B, C> project) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method EnumerableM<B> SelectMany <B> (Func<A, IEnumerable<B>> bind) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method EnumerableM<C> SelectMany <B, C> (Func<A, IEnumerable<B>> bind, Func<A, B, C> project) Source #

Monadic bind (flatmap) of the sequence

Parameters

type B

Bound return value type

param bind

Bind function

returns

Flat-mapped sequence

method EnumerableM<A> Filter (Func<A, bool> f) Source #

Filter the items in the sequence

Parameters

param f

Predicate to apply to the items

returns

Filtered sequence

method EnumerableM<A> Where (Func<A, bool> f) Source #

Filter the items in the sequence

Parameters

param f

Predicate to apply to the items

returns

Filtered sequence

method bool Any () Source #

Returns true if the sequence has items in it

Parameters

returns

True if the sequence has items in it

method EnumerableM<A> Intersperse (A value) Source #

Inject a value in between each item in the sequence

Parameters

type A

Bound type

param ma

Sequence to inject values into

param value

Item to inject

returns

A sequence with the values injected

method int GetHashCode () Source #

Get the hash code for all of the items in the sequence, or 0 if empty

Parameters

returns

method int CompareTo (object? obj) Source #

method string ToString () Source #

Format the collection as [a, b, c, ...] The ellipsis is used for collections over 50 items To get a formatted string with all the items, use ToFullString or ToFullArrayString.

method string ToFullString (string separator = ", ") Source #

Format the collection as a, b, c, ...

method string ToFullArrayString (string separator = ", ") Source #

Format the collection as [a, b, c, ...]

method EnumerableM<A> Combine (EnumerableM<A> y) Source #

method bool Equals <EqA> (EnumerableM<A> rhs) Source #

where EqA : Eq<A>

Equality test

method bool Equals (EnumerableM<A>? other) Source #

method EnumerableM<A> Skip (int amount) Source #

Skip count items

method EnumerableM<A> Take (int amount) Source #

Take count items

method EnumerableM<A> TakeWhile (Func<A, bool> pred) Source #

Iterate the sequence, yielding items if they match the predicate provided, and stopping as soon as one doesn't

Parameters

returns

A new sequence with the first items that match the predicate

method EnumerableM<A> TakeWhile (Func<A, int, bool> pred) Source #

Iterate the sequence, yielding items if they match the predicate provided, and stopping as soon as one doesn't. An index value is also provided to the predicate function.

Parameters

returns

A new sequence with the first items that match the predicate

method (EnumerableM<A> First, EnumerableM<A> Second) Partition (Func<A, bool> predicate) Source #

Partition a list into two based on a predicate

Parameters

param predicate

True if the item goes in the first list, false for the second list

returns

Pair of lists

method int CompareTo <OrdA> (EnumerableM<A> rhs) Source #

where OrdA : Ord<A>

Compare to another sequence

method IEnumerator<A> GetEnumerator () Source #

method EnumerableM<B> Cast <B> () Source #

method EnumerableM<(A First, B Second)> Zip <B> (IEnumerable<B> rhs) Source #

method EnumerableM<C> Zip <B, C> (IEnumerable<B> rhs, Func<A, B, C> zipper) Source #

Operators

operator + (EnumerableM<A> x, EnumerableM<A> y) Source #

Append operator

operator > (EnumerableM<A> x, EnumerableM<A> y) Source #

Ordering operator

operator >= (EnumerableM<A> x, EnumerableM<A> y) Source #

Ordering operator

operator < (EnumerableM<A> x, EnumerableM<A> y) Source #

Ordering operator

operator <= (EnumerableM<A> x, EnumerableM<A> y) Source #

Ordering operator

class EnumerableMExtensions Source #

Methods

method EnumerableM<A> As <A> (this K<EnumerableM, A> xs) Source #

method EnumerableM<A> AsEnumerableM <A> (this IEnumerable<A> xs) Source #

method EnumerableM<A> Flatten <A> (this EnumerableM<EnumerableM<A>> ma) Source #

Monadic join

method EnumerableM<B> Choose <A, B> (this EnumerableM<A> list, Func<A, Option<B>> selector) Source #

Applies the given function 'selector' to each element of the sequence. Returns the sequence comprised of the results for each element where the function returns Some(f(x)).

Parameters

type A

sequence item type

param list

sequence

param selector

Selector function

returns

Mapped and filtered sequence

method EnumerableM<T> Rev <T> (this EnumerableM<T> list) Source #

class EnumerableM Source #

Cons sequence module Represents a sequence of values in a similar way to IEnumerable, but without the issues of multiple evaluation for key LINQ operators like Skip, Count, etc.

Parameters

type A

Type of the values in the sequence

Methods

method EnumerableM<A> flatten <A> (EnumerableM<EnumerableM<A>> ma) Source #

Monadic join

method EnumerableM<A> empty <A> () Source #

Create an empty sequence

method EnumerableM<A> singleton <A> (A value) Source #

Create an empty sequence

method EnumerableM<A> create <A> () Source #

Create a new empty sequence

Parameters

returns

sequence

method EnumerableM<A> create <A> (params A[] items) Source #

Create a sequence from a initial set of items

Parameters

param items

Items

returns

sequence

method EnumerableM<A> createRange <A> (ReadOnlySpan<A> items) Source #

Create a sequence from an initial set of items

Parameters

param items

Items

returns

sequence

method EnumerableM<A> createRange <A> (IEnumerable<A> items) Source #

Create a sequence from an initial set of items

Parameters

param items

Items

returns

sequence

method EnumerableM<A> generate <A> (int count, Func<int, A> generator) Source #

Generates a sequence of A using the provided delegate to initialise each item.

method EnumerableM<A> repeat <A> (A item, int count) Source #

Generates a sequence that contains one repeated value.

method Option<A> head <A> (EnumerableM<A> list) Source #

Get the item at the head (first) of the sequence or None if the sequence is empty

Parameters

param list

sequence

returns

Optional head item

method EnumerableM<B> choose <A, B> (EnumerableM<A> list, Func<A, Option<B>> selector) Source #

Applies the given function 'selector' to each element of the sequence. Returns the sequence comprised of the results for each element where the function returns Some(f(x)).

Parameters

type A

sequence item type

param list

sequence

param selector

Selector function

returns

Mapped and filtered sequence

method EnumerableM<T> rev <T> (EnumerableM<T> list) Source #

Reverses the sequence (Reverse in LINQ)

Parameters

type T

sequence item type

param list

sequence to reverse

returns

Reversed sequence

method EnumerableM<S> scan <S, T> (EnumerableM<T> list, S state, Func<S, T, S> folder) Source #

Applies a function to each element of the sequence, threading an accumulator argument through the computation. This function takes the state argument, and applies the function to it and the first element of the sequence. Then, it passes this result into the function along with the second element, and so on. Finally, it returns the list of intermediate results and the final result.

Parameters

type S

State type

type T

sequence item type

param list

sequence to fold

param state

Initial state

param folder

Folding function

returns

Aggregate state

method EnumerableM<S> scanBack <S, T> (EnumerableM<T> list, S state, Func<S, T, S> folder) Source #

Applies a function to each element of the sequence (from last element to first), threading an accumulator argument through the computation. This function takes the state argument, and applies the function to it and the first element of the sequence. Then, it passes this result into the function along with the second element, and so on. Finally, it returns the list of intermediate results and the final result.

Parameters

type S

State type

type T

Enumerable item type

param list

Enumerable to fold

param state

Initial state

param folder

Folding function

returns

Aggregate state

method EnumerableM<V> zip <T, U, V> (EnumerableM<T> list, EnumerableM<U> other, Func<T, U, V> zipper) Source #

Joins two sequences together either into a single sequence using the join function provided

Parameters

param list

First sequence to join

param other

Second sequence to join

param zipper

Join function

returns

Joined sequence

method EnumerableM<(T Left, U Right)> zip <T, U> (EnumerableM<T> list, EnumerableM<U> other) Source #

Joins two sequences together either into an sequence of tuples

Parameters

param list

First sequence to join

param other

Second sequence to join

param zipper

Join function

returns

Joined sequence of tuples

method EnumerableM<T> distinct <T> (EnumerableM<T> list) Source #

Return a new sequence with all duplicate values removed

Parameters

type T

sequence item type

param list

sequence

returns

A new sequence with all duplicate values removed

method EnumerableM<T> distinct <EQ, T> (EnumerableM<T> list) Source #

where EQ : Eq<T>

Return a new sequence with all duplicate values removed

Parameters

type T

sequence item type

param list

sequence

returns

A new sequence with all duplicate values removed

method EnumerableM<T> distinct <T, K> (EnumerableM<T> list, Func<T, K> keySelector, Option<Func<K, K, bool>> compare = default) Source #

Return a new sequence with all duplicate values removed

Parameters

type T

sequence item type

param list

sequence

returns

A new sequence with all duplicate values removed

method EnumerableM<T> take <T> (EnumerableM<T> list, int count) Source #

Returns a new sequence with the first 'count' items from the sequence provided

Parameters

type T

sequence item type

param list

sequence

param count

Number of items to take

returns

A new sequence with the first 'count' items from the sequence provided

method EnumerableM<T> takeWhile <T> (EnumerableM<T> list, Func<T, bool> pred) Source #

Iterate the sequence, yielding items if they match the predicate provided, and stopping as soon as one doesn't

Parameters

type T

sequence item type

param list

sequence

param count

Number of items to take

returns

A new sequence with the first items that match the predicate

method EnumerableM<T> takeWhile <T> (EnumerableM<T> list, Func<T, int, bool> pred) Source #

Iterate the sequence, yielding items if they match the predicate provided, and stopping as soon as one doesn't. An index value is also provided to the predicate function.

Parameters

type T

sequence item type

param list

sequence

param count

Number of items to take

returns

A new sequence with the first items that match the predicate

method (EnumerableM<T>, EnumerableM<T>) span <T> (EnumerableM<T> self, Func<T, bool> pred) Source #

Span, applied to a predicate 'pred' and a list, returns a tuple where first element is longest prefix (possibly empty) of elements that satisfy 'pred' and second element is the remainder of the list:

Parameters

type T

List element type

param self

List

param pred

Predicate

returns

Split list

Examples

Seq.span(Seq(1,2,3,4,1,2,3,4), x => x < 3) == (Seq(1,2), Seq(3,4,1,2,3,4))

Seq.span(Seq(1,2,3), x => x < 9) == (Seq(1,2,3), Seq())

Seq.span(Seq(1,2,3), x => x < 0) == (Seq(), Seq(1,2,3))